<?php

class Location
{
    public static $default=110100;
    public static $defaultPetRatio=90;
    
	private static $IDs=array({IDs});

	public static function loadLocation($id)
	{
		if(!self::exists($id))
			throw new CException("unknown location[$id]");

        $classname='Location_'.$id;
        return call_user_func(array($classname, 'getInstance'));
	}

	public static function exists($id)
	{
		return array_key_exists($id, self::$IDs);
	}

	public function createEnemy()
	{
		$enemyCount=count($this->enemies);
		if($enemyCount==0)
			throw new CException('no enemies in location['.$this->Id.']');

        $enemyCategories=array_keys($this->enemies);
		$enemyCategory=$enemyCategories[mt_rand(0,$enemyCount-1)];
        $enemyOption=$this->enemies[$enemyCategory];

        if(isset($enemyOption['attackSkills'])) {
		    foreach($enemyOption['attackSkills'] as &$value){
			    if(is_string($value)) $value=(eval($value));
		    }
        }
        if(isset($enemyOption['helpSkills'])) {
            foreach($enemyOption['helpSkills'] as &$value){
                if(is_string($value)) $value=(eval($value));
            }
        }

		if(is_string($enemyOption['level']))
			$enemyOption['level']=eval($enemyOption['level']);

        if(!isset($enemyOption['ratio']))
            $enemyOption['ratio']=$this->defaultPetRatio;

		return PetCategory::loadPetCategory($enemyCategory)->createPet($enemyOption);
	}
}

?>
